/**
 * Class neighbourhood
 * 
 * @author Hussein Patwa
 * @date 10 April 2008 - Rev 07 May 2008
 * @version 3.0 Generate neighbourhood information from map matrix
 */
package trend;

import java.util.*;

@SuppressWarnings("all")
public class NeighbourhoodInfo extends Matrix {

  /** Creates a new instance of NeighbourhoodInfo */
  public NeighbourhoodInfo() {
    super();
  }

  /** Creates a new instance of NeighbourhoodInfo */
  public NeighbourhoodInfo(Vector dat) {
    super(dat);
  }

  /** Determine if adjoining rows are neighbours */
  public boolean areNeighbours(int a1, int a2) {
    // first retrieve the row for a1
    // then retrieve the element at a2 in that row
    // if that element is non-zero return true else return false
    Vector rowV = (Vector) data.get(a1);
    Double rtn = (Double) rowV.get(a2);
    if (rtn.doubleValue() != 0)
      return true;
    else
      return false;
  }

  /**
   * Get the IDs of areas on the map
   * 
   * @param area An area on the map
   * @return vector
   */
  public Vector getNeighbourhoodAreaIDs(int area) {
    Vector rtn = new Vector();
    Vector row = (Vector) data.get(area);
    for (int i = 0; i < row.size(); i++) {
      if (areNeighbours(area, i)) {
        rtn.add(new Integer(i));
      }
    }
    return rtn;
  }
}
